home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Text⁄Files / FONT->NFNT source code / FONT->NFNT.c < prev   
Encoding:
C/C++ Source or Header  |  1991-01-14  |  44.8 KB  |  1,342 lines  |  [TEXT/KAHL]

  1. /*----------------------------------------------------------------------------+
  2. |                                                                             |
  3. |   FONT->NFNT.c                                                              |
  4. |                                                                             |
  5. |   This program is designed to convert FONT resources in a file to NFNT      |
  6. |   resources with the identical resource ID (assuming no ID conflict) and    |
  7. |   name, deleting the original FONT resources.  It can also do the more      |
  8. |   general conversion from any one type of resource to any other resource    |
  9. |   type.  This source code is free for you to modify and use, but as it      |
  10. |   is currently written (and compiled into the FONT->NFNT application        |
  11. |   accompanying this source), it is not Public Domain (i.e. you can use      |
  12. |   parts of this code as you wish in your own programs, but as written by    |
  13. |   me, you cannot distribute for any fee).                                   |
  14. |                                                                             |
  15. +----------------------------------------------------------------------------*/
  16.  
  17. #ifndef _MacProtos_
  18. typedef ProcPtr FilterProc;
  19. #endif
  20.  
  21. #ifndef _H_QuickSort
  22. #include "_QuickSort.h"
  23. #endif
  24.  
  25.  
  26. /* Defines--General */
  27. #define NIL_POINTER                        0L
  28. #define NIL_HANDLE                        (Handle)NIL_POINTER
  29. #define NIL_ACTION_PROC                    NIL_POINTER
  30. #define NO_FILTER_PROC                    NIL_POINTER
  31. #define NIL_PROCPTR                        NIL_POINTER
  32. #define NIL_STRING                        (StringPtr)"\p"
  33. #define NIL_TITLE                        NIL_STRING
  34. #define NIL_REF_CON                        NIL_POINTER
  35.  
  36. #define MOVE_TO_FRONT                    (WindowPtr)-1L
  37. #define REMOVE_ALL_EVENTS                0
  38. #define NORMAL_UPDATES                    TRUE
  39. #define PLAIN                            0
  40. #define LEAVE_WHERE_IT_IS                FALSE
  41.  
  42. #define MIN_SLEEP                        0L
  43. #define NIL_MOUSE_REGION                0L
  44. #define WNE_TRAP_NUM                    0x60
  45. #define UNIMPL_TRAP_NUM                    0x9F
  46.  
  47. #define SCROLL_BAR_PIXEL_WIDTH            15
  48. #define WIDTH                            2
  49.  
  50. #define NO_ERR                            0
  51. #define CANCELLED                        -1
  52.  
  53. #define MOVE_RIGHT_ARROW_CHAR            0x1D    /* ->    */
  54. #define MOVE_LEFT_ARROW_CHAR            0x1C    /* <-    */
  55. #define MOVE_DOWN_ARROW_CHAR            0x1F    /* down-arrow    */
  56. #define MOVE_UP_ARROW_CHAR                0x1E    /* up-arrow    */
  57.  
  58. #define BASE_RES_ID                        400
  59.  
  60.  
  61. /* Defines--Menu */
  62. #define APPLE_ABOUT_ITEM                1
  63.  
  64. #define FILE_FONTNFNT_ITEM                1
  65. #define FILE_CONVERT_ITEM                2
  66. #define FILE_QUIT_ITEM                    4
  67.  
  68. #define EDIT_UNDO_ITEM                    1
  69. #define EDIT_CUT_ITEM                    3
  70. #define EDIT_COPY_ITEM                    4
  71. #define EDIT_PASTE_ITEM                    5
  72. #define EDIT_CLEAR_ITEM                    6
  73.  
  74. #define NOT_A_NORMAL_MENU                -1
  75. #define APPLE_MENU_ID                    BASE_RES_ID
  76. #define FILE_MENU_ID                    BASE_RES_ID+1
  77. #define EDIT_MENU_ID                    BASE_RES_ID+2
  78.  
  79. #define WHOLE_MENU                        0
  80.  
  81.  
  82. /* Defines--DLOG */
  83. #define ARE_YOU_SURE_DLOG_ID            BASE_RES_ID
  84. #define ARE_YOU_SURE_DLOG_OK_ITEM        1
  85. #define ARE_YOU_SURE_DLOG_CANCEL_ITEM    2
  86. #define ARE_YOU_SURE_DLOG_ALL_ITEM        3
  87. #define ARE_YOU_SURE_DLOG_USER_ITEM        4
  88. #define ARE_YOU_SURE_DLOG_DEFAULT_ITEM    5
  89.  
  90. #define ERROR_ALERT_ID                    BASE_RES_ID+1
  91. #define RES_ERROR_ALERT_ID                BASE_RES_ID+2
  92.  
  93. #define ABOUT_DLOG_ID                    BASE_RES_ID+3
  94. #define ABOUT_DLOG_OK_ITEM                1
  95. #define ABOUT_DLOG_PICT_ITEM            2
  96. #define ABOUT_DLOG_ICON_ITEM            3
  97. #define ABOUT_DLOG_DEFBUT_ITEM            4
  98. #define NUM_DLOG_ICONS                    17
  99. #define BASE_ICON_ID                    128
  100. #define BASE_PICT_ID                    128
  101.  
  102. #define UNIQUEID_ALERT_ID                BASE_RES_ID+4
  103. #define UNIQUEID_ALERT_CANCEL_ITEM        1
  104. #define UNIQUEID_ALERT_OVERWRITE_ITEM    2
  105. #define UNIQUEID_ALERT_UNIQUEID_ITEM    3
  106.  
  107. #define CHOOSE_RESTYPE_DLOG_ID            BASE_RES_ID+5
  108. #define CHOOSE_RESTYPE_DLOG_OK_ITEM        1
  109. #define CHOOSE_RESTYPE_DLOG_CANCEL_ITEM    2
  110. #define CHOOSE_RESTYPE_DLOG_USER_ITEM    3
  111. #define CHOOSE_RESTYPE_DLOG_DEFBUT_ITEM    4
  112.  
  113. #define NO_RESOURCES_ALRT_ID            BASE_RES_ID+6
  114.  
  115. #define CHOOSE_RESTYPE2_DLOG_ID            BASE_RES_ID+7
  116. #define CHOOSE_RESTYPE2_DLOG_OK_ITEM        1
  117. #define CHOOSE_RESTYPE2_DLOG_CANCEL_ITEM    2
  118. #define CHOOSE_RESTYPE2_DLOG_TEXT_ITEM        3
  119. #define CHOOSE_RESTYPE2_DLOG_DEFBUT_ITEM    4
  120.  
  121. #define SAME_TYPE_ALRT_ID                BASE_RES_ID+8
  122.  
  123. #define OPERATION_COMPLETE_ALRT_ID        BASE_RES_ID+9
  124.  
  125. /* Defines--STR# */
  126. #define DEFAULT_STRN_ID                    BASE_RES_ID
  127. #define DEFAULT_STRN_CONVERT            5
  128. #define DEFAULT_STRN_ARROW                6
  129. #define DEFAULT_STRN_CONVERSION            8
  130. #define DEFAULT_STRN_OPENING            10
  131. #define DEFAULT_STRN_HANDTOHAND            11
  132. #define OUT_OF_MEMORY                    12
  133. #define CANT_GET_FONT_RESOURCE            13
  134. #define    DEFAULT_STRN_RMVERESOURCE        14
  135. #define    DEFAULT_STRN_SETHANDSIZE        15
  136. #define    DEFAULT_STRN_ADDRESOURCE        16
  137. #define NO_MENU_BAR                        20
  138. #define NO_APPLE_MENU                    21
  139. #define NO_FILE_MENU                    22
  140. #define NO_EDIT_MENU                    23
  141. #define NO_ABOUT_ALERT                    25
  142. #define BLANK_ALERT                        NO_MENU_BAR
  143.  
  144. #define STYLE_STRN_ID                    BASE_RES_ID+1
  145.  
  146.  
  147.  
  148.  
  149. /* Macros */
  150. #define _PStrCopy(src,dest) BlockMove(src,dest,src[0]+1)
  151. #define _LongToPString(theLong,theString) theString[0]=4;BlockMove(&theLong,theString+1,4)
  152. #define _PStringToLong(theString,theLong) BlockMove(theString+1,&theLong,4)
  153.  
  154.  
  155.  
  156. /* Structures */
  157. struct resourceData { Handle  handle;
  158.                       int     ID;
  159.                       Str255  name;
  160.                       Boolean useThisOne;
  161.                      };
  162. typedef struct resourceData ResourceData;
  163. typedef ResourceData *ResourceDataPtr;
  164. #define RESOURCEDATA_SIZE    sizeof(ResourceData)
  165.  
  166.  
  167.  
  168. /* Global Declarations */
  169. ListHandle        _gListH;
  170. Point            _gWhere;
  171. pascal Boolean    _MyModalProc();
  172. pascal Boolean    _ChooseResType2ModalProc();
  173. int                _MenuBarInit();
  174. int                _gModifiers;
  175. Rect            _gListRect;
  176. MenuHandle        _gAppleMenuH;
  177. MenuHandle        _gFileMenuH;
  178. MenuHandle        _gEditMenuH;
  179. Boolean            _gWNEImplemented, _gDone, _gAll;
  180. EventRecord        _gTheEvent;
  181. Handle            *_gPictH, _gIconH[NUM_DLOG_ICONS];
  182. int                _gPictNum, _gIconNum, _gReverse;
  183.  
  184.  
  185. /********** MAIN **********/
  186. main()
  187.   {int _errStrNum;
  188.     _ToolBoxInit();
  189.     if ((_errStrNum=_MenuBarInit())==NO_ERR)
  190.         _MainLoop();
  191.     else
  192.         _DoErrorDialog( 0, _errStrNum, NIL_STRING);
  193.    }
  194.  
  195.  
  196.  
  197. /*********** ToolBoxInit */
  198. _ToolBoxInit()
  199.   {pascal void _RestartProc();
  200.     MaxApplZone();
  201.     InitGraf( (Ptr) &thePort);
  202.     InitFonts();
  203.     FlushEvents( everyEvent, 0);
  204.     InitWindows();
  205.     InitMenus();
  206.     TEInit();
  207.     InitDialogs( (ProcPtr)_RestartProc );
  208.     InitCursor();
  209.    }
  210.  
  211.  
  212.  
  213. /* when the world comes to an end */
  214. pascal void _RestartProc()    { ExitToShell(); }
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221. /************* MenuBarInit *********/
  222. /* init the menu-bar and return TRUE if error-free */
  223. int _MenuBarInit()
  224.   {Handle  _myMenuBar;
  225.    Boolean _error;
  226.    int     _errno;
  227.  
  228.     _myMenuBar = GetNewMBar( BASE_RES_ID );
  229.     if (_myMenuBar==NIL_HANDLE)
  230.         return( NO_MENU_BAR );
  231.     SetMenuBar( _myMenuBar );
  232.     _gAppleMenuH = GetMHandle( APPLE_MENU_ID );
  233.     if (_gAppleMenuH==(MenuHandle)NIL_HANDLE)
  234.         return( NO_APPLE_MENU );
  235.     AddResMenu( _gAppleMenuH, 'DRVR' );
  236.     _gFileMenuH = GetMHandle( FILE_MENU_ID );
  237.     if (_gFileMenuH==(MenuHandle)NIL_HANDLE)
  238.         return( NO_APPLE_MENU );
  239.     _gEditMenuH = GetMHandle( EDIT_MENU_ID );
  240.     if (_gEditMenuH==(MenuHandle)NIL_HANDLE)
  241.         return( NO_EDIT_MENU );
  242.     DrawMenuBar();
  243.     return( NO_ERR );
  244.    }
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251. /********************* Do Error Dialog ***************/
  252. _DoErrorDialog( _errno, _errStrNum, _fn )
  253.   int     _errno, _errStrNum;
  254.   Str255  _fn;
  255.   {Str255  _theString, _theErrNoString;
  256.     if (_errStrNum >= BLANK_ALERT)
  257.       { GetIndString( _theString, DEFAULT_STRN_ID, _errStrNum );
  258.         ParamText( _theString, NIL_STRING, NIL_STRING, NIL_STRING );
  259.         if (StopAlert( RES_ERROR_ALERT_ID, NIL_POINTER ) != 1)
  260.             SysBeep(20);
  261.        }
  262.     else
  263.       { NumToString( (long)_errno, _theErrNoString );
  264.         GetIndString( _theString, DEFAULT_STRN_ID, _errStrNum );
  265.         ParamText( _theErrNoString, _theString, _fn, NIL_STRING );
  266.         if (StopAlert( ERROR_ALERT_ID, NIL_POINTER ) != 1)
  267.             SysBeep(20);
  268.        }
  269.    }
  270.  
  271.  
  272.  
  273.  
  274. /*************** MainLoop ***************/
  275. _MainLoop()
  276.   { _gWNEImplemented = ( NGetTrapAddress( WNE_TRAP_NUM, ToolTrap) !=
  277.                          NGetTrapAddress( UNIMPL_TRAP_NUM, ToolTrap ) );
  278.     _gDone = FALSE;
  279.     while (!_gDone)
  280.         _HandleEvent();
  281.    }
  282.  
  283.  
  284.  
  285. /*************** HandleEvent ***********/
  286. _HandleEvent()
  287.   {char       _theChar;
  288.    WindowPtr  _whichWindow;
  289.    int        _thePart;
  290.    long       _menuChoice;
  291.    Boolean    _cmdKey, _optionKey, _shiftKey, _controlKey, _alphaLock;
  292.  
  293.     if (_gWNEImplemented)
  294.         WaitNextEvent( everyEvent, &_gTheEvent, MIN_SLEEP, NIL_MOUSE_REGION);
  295.     else
  296.       { SystemTask();
  297.         GetNextEvent( everyEvent, &_gTheEvent );
  298.        }
  299.     switch (_gTheEvent.what)
  300.       { case nullEvent:
  301.                  _HandleNull();
  302.                  break;
  303.         case mouseDown:
  304.                  _thePart = FindWindow( _gTheEvent.where, &_whichWindow );
  305.                  if (_thePart == inMenuBar)
  306.                    { _menuChoice = MenuSelect( _gTheEvent.where );
  307.                      _HandleMenuChoice( _menuChoice );
  308.                     }
  309.                  break;
  310.         case keyDown:
  311.         case autoKey:
  312.                  _theChar = _gTheEvent.message & charCodeMask;
  313.                  _cmdKey     = ( (_gTheEvent.modifiers & cmdKey)     != 0 );
  314.                  _optionKey  = ( (_gTheEvent.modifiers & optionKey)  != 0 );
  315.                  _shiftKey   = ( (_gTheEvent.modifiers & shiftKey)   != 0 );
  316.                  _controlKey = ( (_gTheEvent.modifiers & controlKey) != 0 );
  317.                  _alphaLock  = ( (_gTheEvent.modifiers & alphaLock)  != 0 );
  318.                  if ( _cmdKey )
  319.                      _HandleMenuChoice( MenuKey(_theChar)  );
  320.                  if ( (!_optionKey) && (!_shiftKey) && _alphaLock &&
  321.                       ( (_controlKey&&(!_cmdKey)&&(_theChar=0x03)) ||
  322.                         ((!_controlKey)&&_cmdKey&&(_theChar='.' )) ) )
  323.                      _gDone = TRUE;
  324.                  break;
  325.        }
  326.    }
  327.  
  328.  
  329.  
  330.  
  331. /************* HandleNull ***************/
  332. _HandleNull()
  333.   { 
  334.    }
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341. /********** HandleMenuChoice *********/
  342. _HandleMenuChoice( _menuChoice )
  343.   long int  _menuChoice;
  344.   {int  _theMenu, _theItem;
  345.     if (_menuChoice != 0)
  346.       { _theMenu = HiWord( _menuChoice );
  347.         _theItem = LoWord( _menuChoice );
  348.         switch (_theMenu)
  349.           { case APPLE_MENU_ID:
  350.                      _HandleAppleChoice( _theItem );
  351.                      break;
  352.             case FILE_MENU_ID:
  353.                      _HandleFileChoice( _theItem );
  354.                      break;
  355.             case EDIT_MENU_ID:
  356.                      break;
  357.            }
  358.         HiliteMenu( 0 );
  359.        }
  360.    }
  361.  
  362.  
  363.  
  364. /********************* Draw Default Button ***************/
  365. pascal void _DrawDefaultButton( _theDialog, _theItem )
  366.   DialogPtr  _theDialog;
  367.   int        _theItem;
  368.   {int        _itemType;
  369.    Handle     _itemH;
  370.    Rect       _itemRect;
  371.     GetDItem( _theDialog, _theItem, &_itemType, &_itemH, &_itemRect );
  372.     PenSize( 3, 3 );
  373.     FrameRoundRect( &_itemRect, 16, 16 );
  374.    }
  375.  
  376.  
  377.  
  378.  
  379. /********************* Draw PICT ***************/
  380. pascal void _DrawPICT( _theDialog, _theItem )
  381.   DialogPtr  _theDialog;
  382.   int        _theItem;
  383.   {int        _itemType;
  384.    Handle     _itemH;
  385.    Rect       _itemRect;
  386.     GetDItem( _theDialog, _theItem, &_itemType, &_itemH, &_itemRect );
  387.     DrawPicture( (PicHandle)_gPictH[_gPictNum], &_itemRect );
  388.    }
  389.  
  390.  
  391.  
  392.  
  393. /********************* Draw ICON ***************/
  394. pascal void _DrawICON( _theDialog, _theItem )
  395.   DialogPtr  _theDialog;
  396.   int        _theItem;
  397.   {int        _itemType;
  398.    Handle     _itemH;
  399.    Rect       _itemRect;
  400.     GetDItem( _theDialog, _theItem, &_itemType, &_itemH, &_itemRect );
  401.     PlotIcon( &_itemRect, _gIconH[_gIconNum] );
  402.    }
  403.  
  404.  
  405.  
  406.  
  407. /************** HandleAppleChoice **********/
  408. _HandleAppleChoice( _theItem )
  409.   int  _theItem;
  410.   {Str255     _accName;
  411.    int        _accNumber, _itemHit, i, j, _itemType, _numPICTs;
  412.    Handle     _itemH;
  413.    Rect       _box, _pictBox;
  414.    RgnHandle  _upRgn, _pictRgn;
  415.    long int   _count;
  416.    short int  _itemNumber;
  417.    DialogPtr  _aboutDialogP;
  418.    Boolean    _dialogDone;
  419.    GrafPtr    _oldPort;
  420.     switch (_theItem)
  421.       { case APPLE_ABOUT_ITEM:
  422.                  _aboutDialogP = GetNewDialog( ABOUT_DLOG_ID, NIL_POINTER,
  423.                                                MOVE_TO_FRONT );
  424.                  if (_aboutDialogP == (DialogPtr) NIL_POINTER)
  425.                      _DoErrorDialog( 0, NO_ABOUT_ALERT, NIL_STRING );
  426.                  _dialogDone = FALSE;
  427.                  GetDItem( _aboutDialogP, ABOUT_DLOG_DEFBUT_ITEM,
  428.                            &_itemType, &_itemH, &_box );
  429.                  SetDItem( _aboutDialogP, ABOUT_DLOG_DEFBUT_ITEM,
  430.                            _itemType, (Handle)_DrawDefaultButton, &_box );
  431.                  GetDItem( _aboutDialogP, ABOUT_DLOG_PICT_ITEM,
  432.                            &_itemType, &_itemH, &_pictBox );
  433.                  SetDItem( _aboutDialogP, ABOUT_DLOG_PICT_ITEM,
  434.                            _itemType, (Handle)_DrawPICT, &_pictBox );
  435.                  _pictRgn = NewRgn();
  436.                  RectRgn( _pictRgn, &_pictBox );
  437.                  _gPictNum = 0;
  438.                  _numPICTs = Count1Resources( 'PICT' );
  439.                  _gPictH = (Handle *) NewPtr( _numPICTs * sizeof(Handle) );
  440.                  for (i=0; i<_numPICTs; i++)
  441.                      _gPictH[i] = (Handle) GetPicture(i+BASE_PICT_ID);
  442.                  GetDItem( _aboutDialogP, ABOUT_DLOG_ICON_ITEM,
  443.                            &_itemType, &_itemH, &_box );
  444.                  SetDItem( _aboutDialogP, ABOUT_DLOG_ICON_ITEM,
  445.                            _itemType, (Handle)_DrawICON, &_box );
  446.                  _gIconNum = 0;
  447.                  for (i=0; i<NUM_DLOG_ICONS; i++)
  448.                      _gIconH[i] = GetIcon(i+BASE_ICON_ID);
  449.                  _upRgn = NewRgn();
  450.                  RectRgn( _upRgn, &_box );
  451.                  ShowWindow( _aboutDialogP );
  452.                  while (!(_dialogDone))
  453.                    { ModalDialog( NIL_POINTER, &_itemHit );
  454.                      switch ( _itemHit )
  455.                        { case ABOUT_DLOG_OK_ITEM:
  456.                                   _dialogDone = TRUE;
  457.                                   break;
  458.                          case ABOUT_DLOG_PICT_ITEM:
  459.                                   if (++_gPictNum >= _numPICTs) _gPictNum=0;
  460.                                   UpdtDialog( _aboutDialogP, _pictRgn );
  461.                                   break;
  462.                          case ABOUT_DLOG_ICON_ITEM:
  463.                                   if (_gPictNum != 0)
  464.                                     { _gPictNum = 0;
  465.                                       UpdtDialog( _aboutDialogP, _pictRgn );
  466.                                      }
  467.                                   for (i=0; i<NUM_DLOG_ICONS; i++)
  468.                                     { _gIconNum = i;
  469.                                       UpdtDialog( _aboutDialogP, _upRgn );
  470.                                       _Pause( 1L );
  471.                                      }
  472.                                   _Pause( 5L );
  473.                                   for (i=NUM_DLOG_ICONS-1; i>=0; i--)
  474.                                     { _gIconNum = i;
  475.                                       UpdtDialog( _aboutDialogP, _upRgn );
  476.                                       _Pause( 1L );
  477.                                      }
  478.                                   _gIconNum = 0;
  479.                                   UpdtDialog( _aboutDialogP, _upRgn );
  480.                                   break;
  481.                         }
  482.                     }
  483.                  for (i=0; i<_numPICTs; i++)
  484.                      ReleaseResource( _gPictH[i] );
  485.                  DisposPtr( (Ptr)_gPictH );
  486.                  for (i=0; i<NUM_DLOG_ICONS; i++)
  487.                      ReleaseResource( _gIconH[i] );
  488.                  DisposHandle( (Handle) _upRgn );
  489.                  DisposDialog( _aboutDialogP );
  490.                  break;
  491.         default:
  492.                  GetItem( _gAppleMenuH, _theItem, _accName );
  493.                  EnableItem( _gEditMenuH, WHOLE_MENU );
  494.                  _accNumber = OpenDeskAcc( _accName );
  495.                  DisableItem( _gEditMenuH, WHOLE_MENU );
  496.                  break;
  497.        }
  498.    }
  499.  
  500.  
  501.  
  502.  
  503. /***************** Handle File Choice ***************/
  504. _HandleFileChoice( _theItem )
  505.   int  _theItem;
  506.   { switch (_theItem)
  507.       { case FILE_FONTNFNT_ITEM:
  508.         case FILE_CONVERT_ITEM:
  509.                  _ChangeFONTtoNFNT( _theItem );
  510.                  break;
  511.         case FILE_QUIT_ITEM:
  512.                  _gDone = TRUE;
  513.                  break;
  514.        }
  515.    }
  516.  
  517.  
  518.  
  519.  
  520. /********************* Draw List ***************/
  521. pascal void _DrawList( _theDialog, _theItem )
  522.   DialogPtr  _theDialog;
  523.   int        _theItem;
  524.   {int        _itemType;
  525.    Handle     _itemH;
  526.    Rect       _itemRect;
  527.     GetDItem( _theDialog, _theItem, &_itemType, &_itemH, &_itemRect );
  528.     PenSize( 1, 1 );
  529.     FrameRect( &_itemRect );
  530.     InsetRect( &_itemRect, WIDTH, WIDTH );
  531.     FrameRect( &_itemRect );
  532.     LUpdate( _theDialog->visRgn, _gListH );
  533.    }
  534.  
  535.  
  536.  
  537.  
  538. /************** Add Num *****************/
  539. _AddNum( _dataPtr, _len, _theNum, _chars )
  540. char *_dataPtr;
  541. int  *_len;
  542. long _theNum;
  543. int  _chars;
  544.   {int     i;
  545.    Str255  _string;
  546.     NumToString( _theNum, _string );
  547.     for (i=1; (i+_string[0])<=_chars; i++)
  548.         _dataPtr[(*_len)++] = 0xCA;
  549.     for (i=1; i<=_string[0]; i++)
  550.         _dataPtr[(*_len)++] = _string[i];
  551.     _dataPtr[(*_len)++] = 0xCA;
  552.     _dataPtr[(*_len)++] = 0xCA;
  553.     _dataPtr[(*_len)++] = 0xCA;
  554.    }
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561. /****************** Pause ********************/
  562. _Pause( _ticks )
  563. long int _ticks;
  564.   { _ticks += TickCount();
  565.     while (TickCount() < _ticks);
  566.    }
  567.  
  568.  
  569.  
  570.  
  571. /************** Flash Control *************/
  572. _FlashControl( _itemH )
  573. ControlHandle  _itemH;
  574.   { HiliteControl( _itemH, 1);
  575.     _Pause( 15L );
  576.     HiliteControl( _itemH, 0);
  577.     _Pause( 5L );
  578.    }
  579.  
  580.  
  581.  
  582. /*********************** Unique 1 ID *****************/
  583. int _Unique1ID( _theType )
  584. ResType _theType;
  585.   {int _theID;
  586.     _theID = 0;
  587.     while (_theID < 128)
  588.         _theID = Unique1ID( _theType );
  589.     return( _theID );
  590.    }
  591.  
  592.  
  593.  
  594.  
  595.  
  596. /*************** Get ResType1 *****************/
  597. Boolean _GetResType1( _type1, _fn, _answer, _errStrNum )
  598. ResType  *_type1;
  599. Str255   _fn;
  600. int      *_answer;
  601. int      *_errStrNum;
  602.   {int        _numTypes, i, j, _num, _len;
  603.    DialogPtr  _dialogPtr;
  604.    Boolean    _dialogDone, _ok;
  605.    ResType    *_type, _theType;
  606.    long       _mask;
  607.    int        _itemHit;
  608.    int        _itemType;
  609.    Handle     _itemH;
  610.    Rect       _itemRect;
  611.    Rect       _dataBounds;
  612.    Point      _cSize;
  613.    char       _dataPtr[256];
  614.    Str255     _string, _oldString;
  615.    
  616.     *_errStrNum = NO_ERR;
  617.     _numTypes = Count1Types();
  618.     if (_numTypes <= 0)
  619.       { ParamText( NIL_STRING, _fn, NIL_STRING, NIL_STRING );
  620.         CautionAlert( NO_RESOURCES_ALRT_ID, NIL_POINTER );
  621.         return( FALSE );
  622.        }
  623.     _dialogPtr = GetNewDialog( CHOOSE_RESTYPE_DLOG_ID,
  624.                                NIL_POINTER, MOVE_TO_FRONT );
  625.     GetDItem( _dialogPtr, CHOOSE_RESTYPE_DLOG_DEFBUT_ITEM,
  626.               &_itemType, &_itemH, &_itemRect );
  627.     SetDItem( _dialogPtr, CHOOSE_RESTYPE_DLOG_DEFBUT_ITEM,
  628.               _itemType,  (Handle)_DrawDefaultButton, &_itemRect );
  629.     GetDItem( _dialogPtr, CHOOSE_RESTYPE_DLOG_USER_ITEM,
  630.               &_itemType, &_itemH, &_itemRect );
  631.     SetDItem( _dialogPtr, CHOOSE_RESTYPE_DLOG_USER_ITEM,
  632.               _itemType,  (Handle)_DrawList, &_itemRect );
  633.     _dataBounds.top    = 0;
  634.     _dataBounds.left   = 0;
  635.     _dataBounds.bottom = _numTypes;
  636.     _dataBounds.right  = 1;
  637.     _cSize.v = 0;
  638.     _cSize.h = 0;
  639.     InsetRect( &_itemRect, WIDTH+1, WIDTH+1 );
  640.     _gListRect = _itemRect;
  641.     _gListRect.right -= SCROLL_BAR_PIXEL_WIDTH;
  642.     _gListH = LNew( &_gListRect, &_dataBounds, _cSize, 0,
  643.                     _dialogPtr, FALSE, FALSE, FALSE, TRUE );
  644.     /* error check.  if error dispose dialog */
  645.     (*_gListH)->selFlags = lOnlyOne; /* only one selection at a time */
  646.     _cSize.h = 0;
  647.     _type = (ResType *) NewPtr( _numTypes * sizeof(ResType) );
  648.     if ((*_answer=MemError()) != noErr)
  649.       { LDispose( _gListH );
  650.         DisposDialog( _dialogPtr );
  651.         return( OUT_OF_MEMORY );
  652.        }
  653.     for (i=0; i<_numTypes; i++)
  654.         Get1IndType( &(_type[i]), i+1 );
  655.     
  656.     _QuickSort( _numTypes, ASCENDING, 1, LONG, _type );
  657.     
  658.     for (i=0; i<_numTypes; i++)
  659.       { _len = 0;
  660.         _num = Count1Resources( _type[i] );
  661.         _AddNum( _dataPtr, &_len, (long)_num, 5 );
  662.         _theType = _type[i];
  663.         _mask = 0x000000FF;
  664.         for (j=3; j>=0; j--)
  665.           { _dataPtr[_len+j] = (char) (_theType & _mask);
  666.             _theType = _theType >> 8;
  667.            }
  668.         _len += 4;
  669.         _cSize.v = i;
  670.         LSetCell( _dataPtr, _len, _cSize, _gListH );
  671.         LSetSelect( FALSE, _cSize, _gListH );
  672.        }
  673.     _cSize.v = 0;
  674.     LSetSelect( TRUE, _cSize, _gListH );
  675.     
  676.     ShowWindow( _dialogPtr );
  677.     LDoDraw( TRUE, _gListH );
  678.     _dialogDone = FALSE;
  679.     _gAll = FALSE;
  680.     _ok = TRUE;
  681.     while (!_dialogDone)
  682.       { ModalDialog( (FilterProc)_MyModalProc, &_itemHit );
  683.         switch ( _itemHit )
  684.           { case CHOOSE_RESTYPE_DLOG_OK_ITEM:
  685.                      _dialogDone = TRUE;
  686.                      break;
  687.             case CHOOSE_RESTYPE_DLOG_CANCEL_ITEM:
  688.                      _dialogDone = TRUE;
  689.                      _ok = FALSE;
  690.                      break;
  691.             case CHOOSE_RESTYPE_DLOG_USER_ITEM:
  692.                      _dialogDone = LClick( _gWhere, _gModifiers, _gListH );
  693.                      break;
  694.            }
  695.        }
  696.     if (_ok)
  697.       { _cSize.h = 0;
  698.         _cSize.v = 0;
  699.         if ((_ok=LGetSelect( TRUE, &_cSize, _gListH )))
  700.             *_type1 = _type[_cSize.v];
  701.        }
  702.     LDispose( _gListH );
  703.     DisposDialog( _dialogPtr );
  704.     DisposPtr( _type );
  705.     return( _ok );
  706.    }
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713. /*************** Get ResType2 *****************/
  714. Boolean _GetResType2( _type1, _type2, _answer, _errStrNum )
  715. ResType  *_type1, *_type2;
  716. int      *_answer, *_errStrNum;
  717.   {int        _numTypes;
  718.    DialogPtr  _dialogPtr;
  719.    Boolean    _dialogDone;
  720.    int        _itemHit;
  721.    int        _itemType;
  722.    Handle     _itemH;
  723.    Rect       _itemRect;
  724.    Str255     _string, _oldString;
  725.    
  726.     *_errStrNum = NO_ERR;
  727.     _dialogPtr = GetNewDialog( CHOOSE_RESTYPE2_DLOG_ID,
  728.                                NIL_POINTER, MOVE_TO_FRONT );
  729.     _LongToPString( (*_type1), _string );
  730.     ParamText( _string, NIL_STRING, NIL_STRING, NIL_STRING );
  731.     GetDItem( _dialogPtr, CHOOSE_RESTYPE2_DLOG_DEFBUT_ITEM,
  732.               &_itemType, &_itemH, &_itemRect );
  733.     SetDItem( _dialogPtr, CHOOSE_RESTYPE2_DLOG_DEFBUT_ITEM,
  734.               _itemType, (Handle)_DrawDefaultButton, &_itemRect );
  735.     GetDItem( _dialogPtr, CHOOSE_RESTYPE2_DLOG_TEXT_ITEM,
  736.               &_itemType, &_itemH, &_itemRect );
  737.     ShowWindow( _dialogPtr );
  738.     _dialogDone = FALSE;
  739.     while (!_dialogDone)
  740.       { ModalDialog( (FilterProc)_ChooseResType2ModalProc, &_itemHit );
  741.         GetIText( _itemH, _string );
  742.         if (_string[0] > 4)
  743.           { SysBeep(20);
  744.             SetIText( _itemH, _oldString );
  745.             _itemHit = 0;
  746.            }
  747.         else
  748.             BlockMove( _string, _oldString, _string[0]+1 );
  749.         switch (_itemHit)
  750.           { case CHOOSE_RESTYPE2_DLOG_OK_ITEM:
  751.                      while (_string[0] < 4) _string[++_string[0]] = 0x20;
  752.                      _PStringToLong( _string , (*_type2) );
  753.                      if (*_type1 == *_type2)
  754.                        { ParamText( _string,    NIL_STRING,
  755.                                     NIL_STRING, NIL_STRING );
  756.                          NoteAlert( SAME_TYPE_ALRT_ID, NIL_POINTER );
  757.                         }
  758.                      else
  759.                          _dialogDone = TRUE;
  760.                      break;
  761.             case CHOOSE_RESTYPE2_DLOG_CANCEL_ITEM:
  762.                      _dialogDone = TRUE;
  763.                      break;
  764.            }
  765.        }
  766.     DisposDialog( _dialogPtr );
  767.     return( _itemHit==CHOOSE_RESTYPE2_DLOG_OK_ITEM );
  768.    }
  769.  
  770.  
  771.  
  772.  
  773. /********** Open The Resource File ********/
  774. Boolean _OpenTheResourceFile( _fileName, _theItem, _vRef2 )
  775. Str255 _fileName;
  776. int    _theItem;
  777. int    *_vRef2;
  778.   {SFTypeList _myTypes;
  779.    SFReply    _reply;
  780.    Point      _SFGwhere = {  90,  82 };
  781.    Point      _SFPwhere = { 106, 104 };
  782.    int        _vRef, _numTypes;
  783.    Boolean    _answer;
  784.     
  785.     _answer = FALSE;
  786.     if (_theItem == FILE_FONTNFNT_ITEM)
  787.       { _numTypes = 2;
  788.         _myTypes[0] = 'FFIL';
  789.         _myTypes[1] = 'rsrc';
  790.        }
  791.     else
  792.         _numTypes = -1;
  793.     _reply.good = FALSE;
  794.     SFGetFile( _SFGwhere, NIL_STRING, NO_FILTER_PROC, _numTypes, &_myTypes,
  795.                NIL_PROCPTR, &_reply);
  796.     if (_reply.good)
  797.       { _PStrCopy( _reply.fName, _fileName );
  798.         _vRef = _reply.vRefNum;
  799.         *_vRef2 = OpenRFPerm( _fileName, _vRef, fsRdWrPerm );
  800.         if (*_vRef2 >= noErr)
  801.           { UseResFile( *_vRef2 );
  802.             _answer = TRUE;
  803.            }
  804.        }
  805.     return( _answer );
  806.    }
  807.  
  808.  
  809.  
  810.  
  811.  
  812.  
  813. /************* Choose Resources **************/
  814. Boolean _ChooseResources( _type1, _type2, _type2String, _buttonString, _fn,
  815.                           _convertReverseString, _numResources,
  816.                           _theResourceDataArray, _answer, _errStrNum )
  817. ResType           _type1, _type2;
  818. Str255            _type2String;
  819. Str255            _buttonString;
  820. Str255            _fn;
  821. Str255            _convertReverseString;
  822. int               *_numResources;
  823. ResourceDataPtr   *_theResourceDataArray;
  824. int               *_answer, *_errStrNum;
  825.   {Str255   _type1String;
  826.    int      i, j, _theID;
  827.    Boolean  _continue;
  828.    
  829.    DialogPtr  _dialogPtr;
  830.    Boolean    _dialogDone;
  831.    int        _itemHit;
  832.    int        _itemType;
  833.    Handle     _itemH;
  834.    Rect       _itemRect;
  835.    
  836.    long       _size;
  837.    int        _len;
  838.    ResType    _theType;
  839.    char       _dataPtr[256];
  840.    Rect       _dataBounds;
  841.    Point      _cSize;
  842.    
  843.     *_errStrNum = NO_ERR;
  844.     *_numResources = Count1Resources( _type1 );
  845.     if (*_numResources == 0 )
  846.       { _LongToPString( _type1, _type1String );
  847.         _type1String[++_type1String[0]] = 0x20;
  848.         ParamText( _type1String, _fn, NIL_STRING, NIL_STRING );
  849.         CautionAlert( NO_RESOURCES_ALRT_ID, NIL_POINTER );
  850.         return( FALSE );
  851.        }
  852.     
  853.     *_theResourceDataArray = (ResourceDataPtr) NewPtr( (*_numResources) *
  854.                                                          RESOURCEDATA_SIZE );
  855.     if ((*_answer=MemError()) != noErr)
  856.       { *_errStrNum = OUT_OF_MEMORY;
  857.         return( FALSE );
  858.        }
  859.     
  860.     _dialogPtr = GetNewDialog( ARE_YOU_SURE_DLOG_ID, NIL_POINTER, MOVE_TO_FRONT);
  861.     GetDItem( _dialogPtr, ARE_YOU_SURE_DLOG_DEFAULT_ITEM,
  862.               &_itemType, &_itemH, &_itemRect );
  863.     SetDItem( _dialogPtr, ARE_YOU_SURE_DLOG_DEFAULT_ITEM,
  864.               _itemType, (Handle)_DrawDefaultButton, &_itemRect );
  865.     GetDItem( _dialogPtr, ARE_YOU_SURE_DLOG_OK_ITEM,
  866.               &_itemType, &_itemH, &_itemRect );
  867.     SetCTitle( (ControlHandle)_itemH, _buttonString );
  868.     GetDItem( _dialogPtr, ARE_YOU_SURE_DLOG_USER_ITEM,
  869.               &_itemType, &_itemH, &_itemRect );
  870.     SetDItem( _dialogPtr, ARE_YOU_SURE_DLOG_USER_ITEM,
  871.               _itemType, (Handle)_DrawList, &_itemRect );
  872.     _dataBounds.top    = 0;
  873.     _dataBounds.left   = 0;
  874.     _dataBounds.bottom = *_numResources;
  875.     _dataBounds.right  = 1;
  876.     _cSize.v = 0;
  877.     _cSize.h = 0;
  878.     InsetRect( &_itemRect, WIDTH+1, WIDTH+1 );
  879.     _gListRect = _itemRect;
  880.     _gListRect.right -= SCROLL_BAR_PIXEL_WIDTH;
  881.     _gListH = LNew( &_gListRect, &_dataBounds, _cSize, 0, _dialogPtr,
  882.                    FALSE, FALSE, FALSE, TRUE );
  883.     
  884.     _cSize.h = 0;
  885.     _continue = TRUE;
  886.     for (i=0; ((i<*_numResources) && _continue); i++)
  887.       { (*_theResourceDataArray)[i].handle = Get1IndResource( _type1, i+1 );
  888.         *_answer = ResError();
  889.         if ( (_continue = (*_answer==noErr)) )
  890.             GetResInfo( (*_theResourceDataArray)[i].handle,
  891.                         &((*_theResourceDataArray)[i].ID), &_theType,
  892.                         (*_theResourceDataArray)[i].name );
  893.         else
  894.             *_errStrNum = CANT_GET_FONT_RESOURCE;
  895.        }
  896.     
  897.     _QuickSort( *_numResources, ASCENDING, 1, RESDATA, *_theResourceDataArray );
  898.  
  899.     for (i=0; ((i<*_numResources) && _continue); i++)
  900.       { _size = GetHandleSize( (*_theResourceDataArray)[i].handle );
  901.         _len = 0;
  902.         _AddNum( _dataPtr, &_len, (long)((*_theResourceDataArray)[i].ID), 6);
  903.         _AddNum( _dataPtr, &_len, _size, 6 );
  904.         for (j=1; j<=((*_theResourceDataArray)[i].name)[0]; j++)
  905.             _dataPtr[_len++] = ((*_theResourceDataArray)[i].name)[j];
  906.         _cSize.v = i;
  907.         LSetCell( _dataPtr, _len, _cSize, _gListH );
  908.         LSetSelect( TRUE, _cSize, _gListH );
  909.        }
  910.     
  911.     if (_continue)
  912.       { _LongToPString( _type1, _type1String );
  913.         ParamText( _convertReverseString, _type1String, _type2String, _fn );
  914.         LDoDraw( TRUE, _gListH );
  915.         ShowWindow( _dialogPtr );
  916.        }
  917.     _dialogDone = FALSE;
  918.     _gAll = TRUE;
  919.     while ((!(_dialogDone) && _continue))
  920.       { ModalDialog( (FilterProc)_MyModalProc, &_itemHit );
  921.         switch ( _itemHit )
  922.           { case ARE_YOU_SURE_DLOG_CANCEL_ITEM:
  923.                      _continue = FALSE;
  924.             case ARE_YOU_SURE_DLOG_OK_ITEM:
  925.                      _dialogDone = TRUE;
  926.                      break;
  927.             case ARE_YOU_SURE_DLOG_USER_ITEM:
  928.                      LClick( _gWhere, _gModifiers, _gListH );
  929.                      break;
  930.             case ARE_YOU_SURE_DLOG_ALL_ITEM:
  931.                      _cSize.h = 0;
  932.                      for (i=0; i<*_numResources; i++)
  933.                        { _cSize.v = i;
  934.                          LSetSelect( TRUE, _cSize, _gListH );
  935.                         }
  936.                      break;
  937.            }
  938.        }
  939.     if ((_itemHit == ARE_YOU_SURE_DLOG_OK_ITEM) && _continue)
  940.       { _cSize.h = 0;
  941.         for (i=0; i<*_numResources; i++)
  942.           { _cSize.v = i;
  943.             if (! (  (*_theResourceDataArray)[i].useThisOne =
  944.                         ( LGetSelect( FALSE, &_cSize, _gListH ) &&
  945.                           ((*_theResourceDataArray)[i].handle != NIL_HANDLE) )))
  946.                 ReleaseResource( (*_theResourceDataArray)[i].handle );
  947.            }
  948.        }
  949.     LDispose( _gListH );
  950.     DisposDialog( _dialogPtr );
  951.     return( _continue );
  952.    }
  953.  
  954.  
  955.  
  956.  
  957.  
  958. /****************** Do Convert *******************/
  959. Boolean _DoConvert( _theResourceDataPtr, _ignoreZero, _type1, _type2,
  960.                     _answer, _errStrNum )
  961. ResourceDataPtr _theResourceDataPtr;
  962. Boolean         _ignoreZero;
  963. ResType         _type1, _type2;
  964. int             *_answer, *_errStrNum;
  965.   {int     _err, i;
  966.    Boolean _doAddResource, _isNoError;
  967.    Str255  _type1String, _type2String, _theIDStr;
  968.    
  969.    Handle  _handle, _newHandle;
  970.    int     _ID;
  971.    
  972.     *_errStrNum = NO_ERR;
  973.     _handle = _theResourceDataPtr->handle;
  974.     _ID     = _theResourceDataPtr->ID;
  975.     if ( (GetHandleSize(_handle)>(Size)0) || (!_ignoreZero) )
  976.       { _newHandle = NIL_HANDLE;
  977.         _newHandle = Get1Resource( _type2, _ID );
  978.         _err = ResError();
  979.         _doAddResource = TRUE;
  980.         _isNoError = TRUE;
  981.         if ( (_newHandle!=NIL_HANDLE) || ((_err!=resNotFound)&&(_err!=noErr)) )
  982.           { NumToString( (long)_ID, _theIDStr );
  983.             _LongToPString( _type1, _type1String );
  984.             _LongToPString( _type2, _type2String );
  985.             _type1String[++_type1String[0]] = ' ';
  986.             _type1String[++_type1String[0]] = 'I';
  987.             _type1String[++_type1String[0]] = 'D';
  988.             _type1String[++_type1String[0]] = '#';
  989.             for (i=1; i<=_theIDStr[0]; i++)
  990.                 _type1String[++_type1String[0]] = _theIDStr[i];
  991.             ParamText( _type2String,  _type1String, _type2String, _theIDStr );
  992.             switch ( CautionAlert(UNIQUEID_ALERT_ID,NIL_POINTER) )
  993.               { case UNIQUEID_ALERT_CANCEL_ITEM:
  994.                          _doAddResource = FALSE;
  995.                          ReleaseResource( _handle );
  996.                          ReleaseResource( _newHandle );
  997.                          break;
  998.                 case UNIQUEID_ALERT_OVERWRITE_ITEM:
  999.                          SetHandleSize( _newHandle, GetHandleSize(_handle) );
  1000.                          if (_isNoError = ((*_answer=MemError())==noErr))
  1001.                            { BlockMove( *_handle, *_newHandle,
  1002.                                         GetHandleSize(_handle) );
  1003.                              ChangedResource( _newHandle );
  1004.                              RmveResource( _handle );
  1005.                              if (!(_isNoError = ((*_answer=ResError())==noErr)))
  1006.                                { *_errStrNum = DEFAULT_STRN_RMVERESOURCE;
  1007.                                  ReleaseResource( _handle );
  1008.                                 }
  1009.                             }
  1010.                          else
  1011.                            { *_errStrNum = DEFAULT_STRN_SETHANDSIZE;
  1012.                              ReleaseResource( _newHandle );
  1013.                              ReleaseResource( _handle );
  1014.                             }
  1015.                          _doAddResource = FALSE;
  1016.                          break;
  1017.                 case UNIQUEID_ALERT_UNIQUEID_ITEM:
  1018.                          _ID = _Unique1ID( _type2 );
  1019.                          ReleaseResource( _newHandle );
  1020.                          break;
  1021.                }
  1022.            }
  1023.         if (_doAddResource && _isNoError)
  1024.           { _newHandle = _handle;
  1025.             if (_isNoError=((*_answer=HandToHand(&_newHandle))==noErr))
  1026.               { AddResource( _newHandle, _type2, _ID,
  1027.                              _theResourceDataPtr->name );
  1028.                 if (_isNoError= ((*_answer=ResError())==noErr))
  1029.                   { RmveResource( _handle );
  1030.                     if (!(_isNoError = ((*_answer=ResError())==noErr)))
  1031.                       { *_errStrNum=DEFAULT_STRN_RMVERESOURCE;
  1032.                         ReleaseResource( _handle );
  1033.                        }
  1034.                    }
  1035.                 else
  1036.                   { *_errStrNum = DEFAULT_STRN_ADDRESOURCE;
  1037.                     DisposHandle( _newHandle );
  1038.                     ReleaseResource( _handle );
  1039.                    }
  1040.                }
  1041.             else
  1042.               { *_errStrNum = DEFAULT_STRN_HANDTOHAND;
  1043.                 ReleaseResource( _handle );
  1044.                }
  1045.            }
  1046.        }
  1047.     return( _isNoError );
  1048.    }
  1049.  
  1050.  
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056. /********** Change FONT to NFNT **********/
  1057. _ChangeFONTtoNFNT( _theItem )
  1058. int _theItem;
  1059.   {int              _vRef, _errStrNum, _answer, _numResources, i;
  1060.    ResourceDataPtr  _theResourceDataArray;
  1061.    Boolean          _continue, _ignoreZero;
  1062.    Str255           _fn, _type2String, _convertReverseString, _buttonString;
  1063.    Str255           _conversionReversalString, _type1String;
  1064.    ResType          _type1, _type2;
  1065.    
  1066.    
  1067.     _continue = TRUE;
  1068.     
  1069.     if (!_OpenTheResourceFile( _fn, _theItem, &_vRef ))
  1070.       { if (_vRef < noErr)
  1071.           { _answer = ResError();
  1072.             _errStrNum = DEFAULT_STRN_OPENING;
  1073.             _continue = FALSE;
  1074.            }
  1075.        }
  1076.     else
  1077.       { switch (_theItem)
  1078.           { case FILE_FONTNFNT_ITEM:
  1079.                      _type1 = 'FONT';
  1080.                      _type2 = 'NFNT';
  1081.                      break;
  1082.             case FILE_CONVERT_ITEM:
  1083.                      if ( (_continue=
  1084.                            _GetResType1(&_type1,_fn,&_answer,&_errStrNum) ) )
  1085.                          _continue = _GetResType2( &_type1, &_type2,
  1086.                                                    &_answer, &_errStrNum );
  1087.                      break;
  1088.            }
  1089.         if (_continue)
  1090.           { switch (_theItem)
  1091.               { case FILE_FONTNFNT_ITEM:
  1092.                 case FILE_CONVERT_ITEM:
  1093.                          GetIndString( _convertReverseString, DEFAULT_STRN_ID,
  1094.                                        DEFAULT_STRN_CONVERT );
  1095.                          GetIndString( _conversionReversalString,
  1096.                                        DEFAULT_STRN_ID,
  1097.                                        DEFAULT_STRN_CONVERSION );
  1098.                          GetIndString( _type2String, DEFAULT_STRN_ID,
  1099.                                        DEFAULT_STRN_ARROW );
  1100.                          BlockMove( &_type2, _type2String+_type2String[0]+1, 4 );
  1101.                          _type2String[0] += 4;
  1102.                          _LongToPString( _type1, _buttonString );
  1103.                          BlockMove( &_type2, _buttonString+7, 4 );
  1104.                          _buttonString[0] = 10;
  1105.                          _buttonString[5] = '-';
  1106.                          _buttonString[6] = '>';
  1107.                          break;
  1108.                }
  1109.             _continue = _ChooseResources( _type1, _type2, _type2String,
  1110.                                           _buttonString, _fn,
  1111.                                           _convertReverseString,
  1112.                                           &_numResources, &_theResourceDataArray,
  1113.                                           &_answer, &_errStrNum );
  1114.            }
  1115.         if (_continue)
  1116.           { _ignoreZero = FALSE;
  1117.             switch (_theItem)
  1118.               { case FILE_FONTNFNT_ITEM:
  1119.                          _ignoreZero = TRUE;
  1120.                 case FILE_CONVERT_ITEM:
  1121.                          for (i=0; ( (i<_numResources) && (_continue)); i++)
  1122.                              if (_theResourceDataArray[i].useThisOne)
  1123.                                 _continue=_DoConvert(&(_theResourceDataArray[i]),
  1124.                                                      _ignoreZero, _type1, _type2,
  1125.                                                      &_answer, &_errStrNum );
  1126.                          while (i<_numResources)
  1127.                              if (_theResourceDataArray[i].useThisOne)
  1128.                                 ReleaseResource(_theResourceDataArray[i].handle);
  1129.                          break;
  1130.                }
  1131.             DisposPtr( _theResourceDataArray );
  1132.            }
  1133.         CloseResFile( _vRef );
  1134.        }
  1135.     if (_continue)
  1136.       { _LongToPString( _type1, _type1String );
  1137.         ParamText( _conversionReversalString, _type1String, _type2String, _fn );
  1138.         NoteAlert( OPERATION_COMPLETE_ALRT_ID, NIL_POINTER );
  1139.        }
  1140.     else if ((!_continue) && (_errStrNum != NO_ERR))
  1141.         _DoErrorDialog( _answer, _errStrNum, _fn );
  1142.    }
  1143.  
  1144.  
  1145.  
  1146.  
  1147.  
  1148. /*********************** Choose ResType2 Modal Proc *****************/
  1149. pascal Boolean _ChooseResType2ModalProc( _theDialogP, _theEvent, _itemHit )
  1150. DialogPtr   _theDialogP;
  1151. EventRecord *_theEvent;
  1152. int         *_itemHit;
  1153.   {char      key;
  1154.    int       _itemType, _part;
  1155.    Handle    _itemH;
  1156.    Rect      _itemRect;
  1157.    GrafPort  *_savePort;
  1158.    Boolean   _answer;
  1159.    
  1160.     GetPort( &_savePort );
  1161.     SetPort( _theDialogP );
  1162.     _answer = FALSE;
  1163.     if ((_theEvent->what == keyDown) || (_theEvent->what == autoKey))
  1164.       { key = _theEvent->message & charCodeMask;
  1165.         switch (key)
  1166.           { case 0x03: /* enter char  */
  1167.             case 0x0D: /* return char */
  1168.                      GetDItem( _theDialogP, CHOOSE_RESTYPE2_DLOG_OK_ITEM,
  1169.                                &_itemType, &_itemH, &_itemRect );
  1170.                      _FlashControl( (ControlHandle)_itemH );
  1171.                      *_itemHit = CHOOSE_RESTYPE2_DLOG_OK_ITEM;
  1172.                      _answer = TRUE;
  1173.                      break;
  1174.             case '.':
  1175.                      if ((_theEvent->modifiers & cmdKey) != 0)
  1176.                        { GetDItem( _theDialogP, CHOOSE_RESTYPE2_DLOG_CANCEL_ITEM,
  1177.                                    &_itemType, &_itemH, &_itemRect );
  1178.                          _FlashControl( (ControlHandle)_itemH );
  1179.                          *_itemHit = CHOOSE_RESTYPE2_DLOG_CANCEL_ITEM;
  1180.                          _answer = TRUE;
  1181.                         }
  1182.                      break;
  1183.            }
  1184.         if (!_answer)
  1185.           { /* can do some character screening here if desired */
  1186.            }
  1187.        }
  1188.     SetPort( _savePort );
  1189.     return( _answer );
  1190.    }
  1191.  
  1192.  
  1193.  
  1194.  
  1195.  
  1196.  
  1197. /*********************** My Modal Proc *****************/
  1198. pascal Boolean _MyModalProc( _theDialogP, _theEvent, _itemHit )
  1199. DialogPtr   _theDialogP;
  1200. EventRecord *_theEvent;
  1201. int         *_itemHit;
  1202.   {char      key;
  1203.    int       _itemType, _part, _selected, _numElements, i, _top;
  1204.    Handle    _itemH;
  1205.    Rect      _itemRect;
  1206.    GrafPort  *_savePort;
  1207.    Boolean   _answer;
  1208.    Point     _cSize;
  1209.    
  1210.     GetPort( &_savePort );
  1211.     SetPort( _theDialogP );
  1212.     _answer = FALSE;
  1213.     if (_theEvent->what == mouseDown)
  1214.       { _gWhere = _theEvent->where;
  1215.         GlobalToLocal( &_gWhere );
  1216.         _gModifiers = _theEvent->modifiers;
  1217.         
  1218.         /* uncomment this for to ignore clicks in the list */
  1219.         /* if (PtInRect(_gWhere,&_gListRect))
  1220.              { _answer = TRUE;
  1221.                *_itemHit = 0;
  1222.               }
  1223.          */
  1224.        }
  1225.     else if ((_theEvent->what == keyDown) || (_theEvent->what == autoKey))
  1226.       { key = _theEvent->message & charCodeMask;
  1227.         switch (key)
  1228.           { case 0x03: /* enter char  */
  1229.             case 0x0D: /* return char */
  1230.                      GetDItem( _theDialogP, ARE_YOU_SURE_DLOG_OK_ITEM,
  1231.                                &_itemType, &_itemH, &_itemRect );
  1232.                      _FlashControl( (ControlHandle)_itemH );
  1233.                      *_itemHit = ARE_YOU_SURE_DLOG_OK_ITEM;
  1234.                      _answer = TRUE;
  1235.                      break;
  1236.             case '.':
  1237.                      if ((_theEvent->modifiers & cmdKey) != 0)
  1238.                        { GetDItem( _theDialogP, ARE_YOU_SURE_DLOG_CANCEL_ITEM,
  1239.                                    &_itemType, &_itemH, &_itemRect );
  1240.                          _FlashControl( (ControlHandle)_itemH );
  1241.                          *_itemHit = ARE_YOU_SURE_DLOG_CANCEL_ITEM;
  1242.                          _answer = TRUE;
  1243.                         }
  1244.                      else
  1245.                          SysBeep(20);
  1246.                      break;
  1247.             case 'a':
  1248.             case 'A':
  1249.                      if (((_theEvent->modifiers & cmdKey) != 0) && _gAll)
  1250.                        { GetDItem( _theDialogP, ARE_YOU_SURE_DLOG_ALL_ITEM,
  1251.                                    &_itemType, &_itemH, &_itemRect );
  1252.                          _FlashControl( (ControlHandle)_itemH );
  1253.                          *_itemHit = ARE_YOU_SURE_DLOG_ALL_ITEM;
  1254.                          _answer = TRUE;
  1255.                         }
  1256.                      else
  1257.                          SysBeep(20);
  1258.                      break;
  1259.             case MOVE_DOWN_ARROW_CHAR:
  1260.             case MOVE_RIGHT_ARROW_CHAR:
  1261.                      _cSize.h = 0;
  1262.                      _cSize.v = 0;
  1263.                      if (LGetSelect( TRUE, &_cSize, _gListH ))
  1264.                        { _selected = _cSize.v;
  1265.                          _numElements = (*_gListH)->dataBounds.bottom;
  1266.                          while ((_cSize.v < _numElements) &&
  1267.                                 (LGetSelect( TRUE, &_cSize, _gListH )))
  1268.                            { if (((_theEvent->modifiers & shiftKey) == 0) ||
  1269.                                                                     (!_gAll))
  1270.                                  LSetSelect( FALSE, _cSize, _gListH );
  1271.                              _selected = _cSize.v++;
  1272.                             }
  1273.                          if (_selected < _numElements-1)
  1274.                              _selected++;
  1275.                          if (((_theEvent->modifiers & cmdKey) != 0) ||
  1276.                              (key == MOVE_RIGHT_ARROW_CHAR))
  1277.                            { for (i=_selected; i<_numElements; i++)
  1278.                                { _cSize.v = i;
  1279.                                  LSetSelect( TRUE, _cSize, _gListH );
  1280.                                 }
  1281.                              _selected = _numElements-1;
  1282.                             }
  1283.                          _cSize.v = _selected;
  1284.                          LSetSelect( TRUE, _cSize, _gListH );
  1285.                          if ((*_gListH)->visible.bottom-1 < _selected)
  1286.                              LScroll( 0, _selected-(*_gListH)->visible.bottom+1,
  1287.                                          _gListH );
  1288.                          *_itemHit = 0;
  1289.                          _answer = TRUE;
  1290.                         }
  1291.                      break;
  1292.             case MOVE_UP_ARROW_CHAR:
  1293.             case MOVE_LEFT_ARROW_CHAR:
  1294.                      _cSize.h = 0;
  1295.                      _cSize.v = 0;
  1296.                      if (LGetSelect( TRUE, &_cSize, _gListH ))
  1297.                        { _numElements = (*_gListH)->dataBounds.bottom;
  1298.                          _selected = _cSize.v;
  1299.                          if (((_theEvent->modifiers & shiftKey) == 0)||(!_gAll))
  1300.                              for (i=_selected; i<_numElements; i++)
  1301.                                { _cSize.v = i;
  1302.                                  LSetSelect( FALSE, _cSize, _gListH );
  1303.                                 }
  1304.                          if (_selected > 0)
  1305.                              _selected--;
  1306.                          if (((_theEvent->modifiers & cmdKey) != 0) ||
  1307.                              (key == MOVE_LEFT_ARROW_CHAR))
  1308.                            { _selected = 0;
  1309.                              if (((_theEvent->modifiers & shiftKey) != 0) &&
  1310.                                                                     (_gAll))
  1311.                                { _top = _cSize.v;
  1312.                                  for (i=0; i<_top; i++)
  1313.                                    { _cSize.v = i;
  1314.                                      LSetSelect( TRUE, _cSize, _gListH );
  1315.                                     }
  1316.                                  _cSize.v = _top;
  1317.                                 }
  1318.                             }
  1319.                          _cSize.v = _selected;
  1320.                          LSetSelect( TRUE, _cSize, _gListH );
  1321.                          if ((*_gListH)->visible.top > _selected)
  1322.                              LScroll( 0, _selected-(*_gListH)->visible.top,
  1323.                                      _gListH );
  1324.                          *_itemHit = 0;
  1325.                          _answer = TRUE;
  1326.                         }
  1327.                      break;
  1328.             default:
  1329.                      SysBeep(20);
  1330.                      break;
  1331.            }
  1332.        }
  1333.     SetPort( _savePort );
  1334.     return( _answer );
  1335.    }
  1336.  
  1337.  
  1338.  
  1339.  
  1340.  
  1341.  
  1342.